# 编写一个函数来查找字符串数组中的最长公共前缀。
#
#  如果不存在公共前缀，返回空字符串 ""。
#
#
#
#  示例 1：
#
#
# 输入：strs = ["flower","flow","flight"]
# 输出："fl"
#
#
#  示例 2：
#
#
# 输入：strs = ["dog","racecar","car"]
# 输出：""
# 解释：输入不存在公共前缀。

class Solution:
    def longestCommonPrefix(self, strs):
        result_str=[]
        n = min(len(str) for str in strs)
        for i in range(n):
            same_str_list=[str[i] for str in strs]
            same_str_list =list(set(same_str_list))
            if len(same_str_list) == 1:
                result_str.append(same_str_list[0])
            else:
                break
        return ''.join(result_str)







strs = ["dog","racecar","car"]
print(Solution().longestCommonPrefix(strs))